/**
 * 
 */
package com.xb.cloud.product.merchant.inner.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.xb.cloud.common.constant.DbConstants;
import com.xb.cloud.product.merchant.inner.service.ProductSerialInnerService;
import com.xb.cloud.product.merchant.service.impl.AbstractService;
import com.xb.cloud.product.service.business.model.ProductSerial;
import com.xb.cloud.product.service.business.model.ProductSerialExample;
import com.xb.cloud.product.service.business.model.mapper.ProductSerialMapper;

/**
 * 商品图片服务类
 * 
 * @author kexue
 *
 */
@Service
public class ProductSerialInnerServiceImpl extends AbstractService implements ProductSerialInnerService {

	private static final Logger LOGGER = LoggerFactory.getLogger(ProductSerialInnerServiceImpl.class);

	@Resource
	private ProductSerialMapper productSerialMapper;

	/**
	 * 通过虚品id获取子品默认品的id;
	 * 
	 * @return
	 */
	@Override
	public Long getDefaultProductIdByVirtualId(Long virtualProductId) {
		ProductSerialExample example = new ProductSerialExample();
		example.createCriteria().andProductIdEqualTo(virtualProductId).andIsMainProductEqualTo(DbConstants.TRUE);

		List<ProductSerial> productSerialRefList = productSerialMapper.selectByExample(example);
		if (productSerialRefList != null && productSerialRefList.size() > 0) {
			ProductSerial productSerial = productSerialRefList.get(0);
			return productSerial.getSubProductId();
		}
		return null;
	}

}
